def prime(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True

def wordtonumber(word):
    numbers = {
        'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4,
        'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9
    }
    return numbers.get(word.lower(), -1)

def findnearestprime(number):
    if number < 2:
        return 2
    lower = number - 1
    upper = number + 1
    while True:
        if prime(lower):
            return lower
        if prime(upper):
            return upper
        lower -= 1
        upper += 1

def main():
    input_words = input().split()
    if len(input_words) != 3 or any(wordtonumber(word) == -1 for word in input_words):
        print("Wrong input")
        return
    number = wordtonumber(input_words[0]) * 100 + wordtonumber(input_words[1]) * 10 + wordtonumber(input_words[2])
    nearest_prime = findnearestprime(number)
    print(nearest_prime)

if __name__ == "__main__":
    main()
